package com.xzc.shopping.model.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
public class CartListVO {
    // 购物车项列表
    private List<CartVO> items;

    // 购物车总金额（所有itemTotal之和）
    private BigDecimal totalAmount;

    public CartListVO(List<CartVO> items) {
        this.items = items;
        this.totalAmount = calculateTotal(items);
    }

    private BigDecimal calculateTotal(List<CartVO> items) {
        return items.stream()
                .map(CartVO::getItemTotal)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
    }
}